import service from "../utils/request.js"

/**
 * 网络请求URL
 */
const base = {
	/**
	 * 请求头
	 */
	header: {
		"content-type": "application/x-www-form-urlencoded"
	},
	header_json: {
		"content-type": "application/json"
	},
	/**
	 * 请求地址
	 */
	// baseUrl: "http://localhost:8083",
	baseUrl: "http://110.41.83.162:8083",
	
	adItem: "/ad/aditem", // 首页广告轮播图
	
	register: "/users/reg", // 注册
	login: "/users/login", // 登录
	getUserInfo:"/users/getUserInfo", // 用户信息
	loginOut:"/users/logOut", // 用户信息
	updateUserInfo:"/users/updateUserInfo",
	getUserHeadImage: "/file/getFile", // 用户头像地址
	
	getAllHost: "/host/getAllHost", // 用户手机号下所有主机
	addHost:"/host/addHost", // 添加主机
	updateHost:"/host/updateHost", // 更新主机信息
	findByPage:"/host/findByPage",// 分页查询主机
	
	plcHand:"/plc/hand", // 开启手动模式
	plcAuto:"/plc/auto", // 开启自动动模式
	plcStart:"/plc/handStart", // 手动模式下启动
	plcStop:"/plc/handStop", // 手动模式下停止
	plcSetFrequency:"/plc/setFrequency", // 设置频率
	plcReadIndexParam:"/plc/readIndexParam", // 读取首页参数
	readRunParamById:"/plc/readRunParamById",//读取运行参数
	writeRepeatParamByJson:"/plc/writeRepeatParamByJson",//写入循环参数
	readRepeatParamById:"/plc/readRepeatParamById",//读取循环参数
	
	getInnerFile:"/file/getFile",//读取内部图片
	/**
	 * 常量
	 */
	userInfoHead:"spray_token",
	userInfo:"user_info",
	userHostList:'user_host_list',
	
}


/**
 * 网络请求方法
 */

function getAdItemList(data){
	return service({
		header:base.header,
		url:base.baseUrl + base.adItem,
		method:"get",
		data
	})
}

function register(data){
	return service({
		header:base.header_json,
		url:base.baseUrl + base.register,
		method:"post",
		data:data
	})
}


function getUserInfo(uuid,data){
	return service({
		header:{
				"content-type": "application/json",
				"spray_token": uuid
		},
		url:base.baseUrl + base.getUserInfo,
		method:"get",
		data:data
	})
}

function updateUserInfo(uuid,data){
	return service({
		header:{
				"content-type": "application/json",
				"spray_token": uuid
		},
		url:base.baseUrl + base.updateUserInfo,
		method:"post",
		data:data
	})
}

function loginOut(uuid,data){
	return service({
		header:{
				"content-type": "application/json",
				"spray_token": uuid
		},
		url:base.baseUrl + base.loginOut,
		method:"get",
		data:data
	})
}

function updateHostById(data){
	return service({
		header:base.header_json,
		url:base.baseUrl + base.updateHost,
		method:"post",
		data:data
	})
}

// function getUserHeadImage(data){
// 	return service({
// 		header:base.header,
// 		url:base.baseUrl + base.getUserHeadImage,
// 		method:"get",
// 		data:data
// 	})
// }
/**
 * 查询用户名下手机
 * @param {Object} data
 * 
 */
function getAllHost(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.getAllHost,
		method:"get",
		data:data
	})
}

function addHost(data){
	return service({
		header: base.header_json,
		url:base.baseUrl + base.addHost,
		method:"post",
		data:data
	})
}
/**
 * PLC 控制接口
 */
function setHand(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcHand,
		method:"get",
		data:data
	})
}

function setAuto(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcAuto,
		method:"get",
		data:data
	})
}

function handStart(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcStart,
		method:"get",
		data:data
	})
}

function handStop(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcStop,
		method:"get",
		data:data
	})
}

function setFrequency(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcSetFrequency,
		method:"get",
		data:data
	})
}

function readIndexParam(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.plcReadIndexParam,
		method:"get",
		data:data
	})
}

function findByPage(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.findByPage,
		method:"get",
		data:data
	})
}

function readRunParamById(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.readRunParamById,
		method:"get",
		data:data
	})
}

function writeRepeatParamByJson(data){
	return service({
		header: base.header_json,
		url:base.baseUrl + base.writeRepeatParamByJson,
		method:"post",
		data:data
	})
}

function readRepeatParamById(data){
	return service({
		header: base.header,
		url:base.baseUrl + base.readRepeatParamById,
		method:"get",
		data:data
	})
}
export default {
	base,
	getAdItemList,
	register,
	getUserInfo,
	loginOut,
	updateUserInfo,
	// getUserHeadImage
	getAllHost,
	addHost,
	updateHostById,
	setHand,
	setAuto,
	handStart,
	handStop,
	setFrequency,
	readIndexParam,
	findByPage,
	readRunParamById,
	writeRepeatParamByJson,
	readRepeatParamById,
	
}